//
//  HNSH_VideoTaskAlert.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/7/11.
//

#import "HNSH_VideoTaskAlert.h"
#import "HNSH_PopupController.h"

@interface HNSH_VideoTaskAlert ()
/* nyPopView */
@property(nonatomic, strong) HNSH_PopupController *nyPopView;

/* iconImgV */
@property (nonatomic, strong) UIImageView *iconImgV;
/* titleLabel */
@property (nonatomic, strong) UILabel *titleLabel;
/* desLabel */
@property (nonatomic, strong) UILabel *desLabel;
/* closeButton */
@property (nonatomic, strong) UIButton *closeButton;
/* button */
@property (nonatomic, strong) UIButton *button;
@end

@implementation HNSH_VideoTaskAlert

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self configUI];
    }
    return self;
}

- (void)showView {
    self.nyPopView = [[HNSH_PopupController alloc]init];
    self.nyPopView.dismissOnMaskTouched = YES;
    self.nyPopView.layoutType = PopupLayoutTypeCenter;
    self.nyPopView.slideStyle = PopupSlideStyleFade;
    [self.nyPopView presentContentView:self duration:0.25 springAnimated:YES inView:kSTWindow];
    self.nyPopView.popupView.layer.cornerRadius = 16.0f;
    self.nyPopView.popupView.layer.masksToBounds = YES;
}

- (void)closeView {
    [self.nyPopView dismissWithDuration:0.25 springAnimated:YES];
}

- (void)setTitleString:(NSString *)titleString {
    _titleString = titleString;
    self.titleLabel.text = titleString;
}

- (void)setDesString:(NSString *)desString {
    _desString = desString;
    self.desLabel.text = desString;
}

- (void)configUI {
    [self addSubview:self.iconImgV];
    [self addSubview:self.titleLabel];
    [self addSubview:self.desLabel];
    [self addSubview:self.closeButton];
    [self addSubview:self.button];
    
    [self.iconImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.top.mas_equalTo(24);
        make.width.mas_equalTo(180);
        make.height.mas_equalTo(130);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.top.mas_equalTo(166);
        make.height.mas_equalTo(28);
    }];
    
    [self.desLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.top.mas_equalTo(202);
        make.height.mas_equalTo(20);
    }];
    
    [self.button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.top.mas_equalTo(246);
        make.width.mas_equalTo(255);
        make.height.mas_equalTo(40);
    }];
    
    [self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(16);
        make.right.mas_equalTo(-16);
        make.width.height.mas_equalTo(16);
    }];
}

#pragma mark lazy
- (UIImageView *)iconImgV {
    if (!_iconImgV) {
        _iconImgV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"mine_video_task_icon"]];
    }
    return _iconImgV;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.textColor = [UIColor appGreenColor];
        _titleLabel.text = @"恭喜你完成任务";
        _titleLabel.font = [UIFont boldSystemFontOfSize:20];
    }
    return _titleLabel;
}

- (UILabel *)desLabel {
    if (!_desLabel) {
        _desLabel = [[UILabel alloc]init];
        _desLabel.textColor = [UIColor appBlackLabelColor];
        _desLabel.font = [UIFont systemFontOfSize:14];
    }
    return _desLabel;
}

- (UIButton *)closeButton {
    if (!_closeButton) {
        _closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_closeButton setImage:[UIImage imageNamed:@"base_icon_close"] forState:UIControlStateNormal];
        __weak __typeof(&*self)weakSelf = self;
        [[_closeButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            [weakSelf closeView];
        }];
    }
    return _closeButton;
}

- (UIButton *)button {
    if (!_button) {
        _button = [UIButton buttonWithType:UIButtonTypeCustom];
        [_button setTitle:@"继续观看" forState:UIControlStateNormal];
        [_button setTitleColor:[UIColor appWhiteLabelColor] forState:UIControlStateNormal];
        _button.titleLabel.font = [UIFont boldSystemFontOfSize:16];
        _button.backgroundColor = [UIColor appGreenColor];
        _button.layer.cornerRadius = 20.0f;
        _button.layer.masksToBounds = YES;
        __weak __typeof(&*self)weakSelf = self;
        [[_button rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            if (weakSelf.videoBlock) {
                weakSelf.videoBlock();
            }
            [weakSelf closeView];
        }];
    }
    return _button;
}

@end
